
import React, { useEffect, useState, useRef, } from 'react';
import { Modal, Form, Space, Button } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect } from 'umi';
import TableDataBlock from '@/components/TableDataBlock';
import { ExclamationCircleOutlined } from '@ant-design/icons'
import { notification } from 'antd';
const DeleteModel = (props) => {
  const { visible = false, onClose, loading, onChange, dispatch, reload } = props;
  const { show, detail = {}, } = visible;
  const { stage } = detail;
  const [form] = Form.useForm();
  const [stageList, setStageList] = useState([])
  // 确认提交
  const { id } = detail
  useEffect(() => {
    if (show) {
      fetchUserStage()
    }
    else {
      setStageList([])

    }
  }, [show])
  const filterList = (list) => {
    return list.map((item) => {
      const { promoterList = [] } = item;
      const localItem = {
        ...item,
        promoterList: promoterList.length ? filterList(promoterList) : undefined,
      };
      return localItem;
    });
  };
  console.log(detail)
  const fetchUserStage = () => {
    dispatch({
      type: 'promoter/fetchListPromoterByOriParent',
      payload: {
        promoterId: id
      },
      callback: (e) => {
        setStageList(filterList(e))
      }
    })
  }


  const modalProps = {
    title: '查看族谱',
    width: 900,
    visible: show,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
    footer: <Space>
      <Button onClick={() => onClose()}>取消</Button>
    </Space>
  };
  const getColumns = [
    {
      title: '姓名',
      dataIndex: 'applyUsername',

    },
    {
      title: '手机',
      dataIndex: 'applyMobile',

    },
    {
      title: '邀请人数',
      dataIndex: 'inviteUserAmount',

    },
    {
      title: '邀请推广员数',
      dataIndex: 'invitePromoterAmount',

    },
    {
      title: '订单数',
      dataIndex: 'saleOrderAmount',

    },
    {
      title: '订单金额',
      dataIndex: 'saleMoney',

    },
  ];
  return (
    <Modal {...modalProps} onCancel={onClose}>
      <TableDataBlock
        loading={loading}
        columns={getColumns}
        rowKey={(record) => `${record.id}`}
        firstFetch={false}
        list={stageList}
        pagination={false}
        expandable={{
          childrenColumnName: "promoterList",
          defaultExpandAllRows: true
        }}
      ></TableDataBlock>
    </Modal >
  );
};

export default connect(({ order, loading }) => ({
  loading: loading.effects['subscriber/fakeReleaseUserStage'],
}))(DeleteModel);
;
